<?php
/*------------------------------------------------------------------------
# com_vportfolio - Vportfolio component
# ------------------------------------------------------------------------
# author    Vsmart Extensions
# copyright Copyright (C) 2010 www.vsmart-extensions.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://www.vsmart-extensions.com
# Technical Support:  Forum - http://www.vsmart-extensions.com
-------------------------------------------------------------------------*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.application.component.view');

/**
 * @package		Joomla
 * @subpackage	Vportfolio
 */
class PortfolioViewPortfolio extends JView
{
	function display($tpl = null)
	{
		global $mainframe, $Itemid;
		
		$pathway	= &$mainframe->getPathway();
		
		$document	= & JFactory::getDocument();
				
		$document->addScript(JURI::base().'components/com_vportfolio/js/jquery.js');	
		$document->addScript(JURI::base().'components/com_vportfolio/js/prettyPhoto.js');	
		$document->addStyleSheet(JURI::base().'components/com_vportfolio/prettyPhoto.css');
		$document->addStyleSheet(JURI::base().'components/com_vportfolio/vportfolio.css');		
		$document->addScript(JURI::base().'components/com_vportfolio/js/jquery.rating.js');	
		$document->addStyleSheet(JURI::base().'components/com_vportfolio/jquery.rating.css');
		$document->addScript(JURI::base().'components/com_vportfolio/js/messages.js');
				
		// Get the parameters of the active menu item
		$menus	= &JSite::getMenu();
		$menu    = $menus->getActive();
		$pparams = &$mainframe->getParams('com_vportfolio');

		// Push a model into the view
		$model		= &$this->getModel();
		$modelCat	= &$this->getModel( 'Category' );

		// Selected Request vars
		// ID may come from the contact switcher
		$itemId	= JRequest::getInt( 'id',			$itemId );
		

		// query options
		$options['id']	= $itemId;

		$item	= $model->getPortfolio( $options );
		$next	= $model->getNextPortfolio( $options );	
		
		$nextlink = JRoute::_("index.php?option=com_vportfolio&task=view&id=".$next->id."&Itemid=".$Itemid);	
		
		$prev	= $model->getPrevPortfolio( $options );	

		$prevlink = JRoute::_("index.php?option=com_vportfolio&task=view&id=".$prev->id."&Itemid=".$Itemid);		

		// check if we have a contact
		if (!is_object( $item )) {
			JError::raiseError( 404, 'Item not found' );
			return;
		}

		$options['category_id']	= $item->categoryId;
		$options['order by']	= 'c.id';

		$items = $modelCat->getPortfolios( $options );

		// Set the document page title
		$document->setTitle(JText::_('Portfolio').' - '.$item->title);
		
		//set breadcrumbs
		$pathway->setPathway(NULL);
		if($pathway->_pathway[0]->name != $item->name)
			$pathway->addItem($item->name, 'index.php?option=com_vportfolio&task=category&catid='.$options['category_id'].'&Itemid=999');
		$pathway->addItem($item->title, '');

		// Adds parameter handling
		$item->params = new JParameter($contact->params);

		$pparams->merge($item->params);
		
		$modelConfig = &JModel::getInstance( 'vportfolioConfigComponentModel' );
		$config = $modelConfig->getConfigParams();
		
		//update hit
		$model->updateHit( $options );
		$item->hit = $item->hit + 1;
		
		$this->assignRef('item',		$item);
		$this->assignRef('nextlink',		$nextlink);
		$this->assignRef('next',		$next);
		$this->assignRef('prevlink',		$prevlink);
		$this->assignRef('prev',		$prev);
		$this->assignRef('items',		$items);
		$this->assignRef('params',		$pparams);
		$this->assignRef('config',		$config);

		parent::display($tpl);
	}
}